import * as Useragent from 'useragent';
import { ClientInfoDto } from '../dto';

export function getClientInfo(req: any): Promise<ClientInfoDto> {
  if (!req?.headers['user-agent']) return Promise.reject('非法请求');
  const agent = Useragent.parse(req.headers['user-agent']);
  const os = agent.os.toJSON().family;
  const browser = agent.toAgent();
  return Promise.resolve({
    userAgent: req.headers['user-agent'],
    ipaddr: req.ip,
    browser: browser,
    os: os,
    location: '',
  });
}
